/**
 * //请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 * //
 * //
 * //
 * // 示例 1：
 * //
 * // 输入：s = "We are happy."
 * //输出："We%20are%20happy."
 * //
 * //
 * //
 * // 限制：
 * //
 * // 0 <= s 的长度 <= 10000
 * //
 * // Related Topics 字符串 👍 322 👎 0
 */

package com.xixi.easy;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ID_Offer_05_TiHuanKongGeLcof {
    public static void main(String[] args) {
        Solution solution = new ID_Offer_05_TiHuanKongGeLcof().new Solution();
    }


    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String replaceSpace(String s) {
            char[] sChar = s.toCharArray();
            List<Character> newChar = new ArrayList<>();
            for (int i = 0; i < s.length(); i++) {
                if (sChar[i] == ' ') {
                    newChar.add('%');
                    newChar.add('2');
                    newChar.add('0');
                } else {
                    newChar.add(sChar[i]);
                }
            }


            Stream<Character> charStream = newChar.stream();
            String newString = charStream.map(String::valueOf).collect(Collectors.joining());
            return newString;

        }
    }
//leetcode submit region end(Prohibit modification and deletion)


}